package com.yuntuzhilian.chapter3;

import java.io.*;

/**
 * @author MrWang-shuizhishuiheshui
 * @description  带有缓冲区的字符读写操作
 */
public class TestBufferedReaderAndBufferedWriter {
    public static void main(String[] args) {
        //声明读入
        Reader rd=null;
        BufferedReader br=null;
        //声明写出
        Writer wr=null;
        BufferedWriter bw=null;

        try {
            //实例化读入
            rd=new FileReader("test3.txt");
            br=new BufferedReader(rd);
            //实例化写出
            wr=new FileWriter("test4.jar");
            bw=new BufferedWriter(wr);
            //创建StringBuilder对象
            StringBuilder sb=new StringBuilder();
            String str=null;
            while((str=br.readLine())!=null){
                sb.append(str);
            }
            bw.write(sb.toString());
            //刷新保存
            bw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bw!=null){
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (br!=null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
